﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;

namespace WFWS.Core
{
    public class HttpHeaderCollection:NameObjectCollectionBase
    {
        public void Set(HttpHeader header)
        {
            //TODO: parse the header more deeply
            BaseSet(header.Name, header);
            OnSet(header);
        }

        private void OnSet(HttpHeader header)
        {
            HeaderSet(this, new HeaderEventArgs(header.Name, header.Value));
        }

        public event EventHandler<HeaderEventArgs> HeaderSet = delegate { };

        public HttpHeader Get(string name)
        {
            return (HttpHeader)BaseGet(name);
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            foreach (var key in Keys)
            {
                sb.Append(Get(key.ToString()).ToString());
                sb.Append(";");
            }
            if (sb.Length > 0)
                return sb.ToString(0, sb.Length - 1);

            return "";
        }
    }
}
